define(window.backboneCommon.getViewDefine("targets.interest"), function ($,require,Collection,tpl) {
    var defaultsOptions={
        submitCallback:null
    };
    var pagePrivate = {
        getDefaults :function () {
            return defaultsOptions
        },
        getOptions : function (options) {
            options=$.ExtCommon.isCheckEmpty(options)?{}:options;
            return $.ExtCommon.initMergeJson(this.getDefaults(),options);
        }
    };
    var backboneView= Backbone.View.extend({
        events: {
            "hidden.bs.modal #modal_targetInterest": "hideModalCallback",
            "click #submit_modal_targetInterest": "saveSubmit"
        },
        initialize: function () {
            this.listenTo(this.model, 'bind:Interest', this.bindInterest);
            this.render();
        },
        render:function(){
            var templateHtml=_.template(tpl);
            this.$el.html(templateHtml());
            return this;
        },
        initMain:function(options){
            this.elementModel={
                interest:$('#panel_modal_targetInterest'),
                modal:$('#modal_targetInterest')
            };
            this.extObject={};
            this.pageData={initPage:false};
            this.pageOptions=$.ExtCommon.initMergeJson(pagePrivate.getOptions(),options);
        },
        initPage:function (json) {
            this.pageData.listSelect=json;
            if(!this.pageData.initPage){
                this.pageData.initPage=true;
                this.collection.initAfterInterest();
            }else{
                this._showModal();
                this.extObject.interest.setSelected(this.pageData.listSelect);
            }
        },
        bindInterest:function () {
            var self=this;
            var res=self.model.get("dataInterest");
            self.extObject.interest=self.elementModel.interest.ExtSelectedMove({
                attrName:"interest",placeholder:"请输入商业兴趣名称",initValue:self.pageData.listSelect, data:res.data,
                initCallback:function(){self._showModal();}
            });
        },
        _checkForm:function () {},
        saveSubmit:function () {
            this._hideModal();
            var jsonData= this.extObject.interest.getSelectedList();
            if(this.pageOptions.submitCallback){this.pageOptions.submitCallback(jsonData);}
        },
        _showModal:function(){
            this.elementModel.modal.modal("show");
            $.ExtAssist.modal.computeTop(this.elementModel.modal);
        },
        _hideModal: function () {
            this.elementModel.modal.modal("hide");
        },
        hideModalCallback:function () {
            this.extObject.interest.clearSelected();
        }
    });
    var viewModel=function(options){
        this.collection= new Collection();
        this.model=this.collection.model;
        this.view=new backboneView({el:options.pElement,collection:this.collection,model:this.model});
        this.view.initMain(options);
    };
    viewModel.prototype={
        init:function (json) {
            this.view.initPage(json);
        }
    };
    return viewModel;
});